package com.hmh.student.students.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmh.student.students.entity.Course;
import com.hmh.student.students.mapper.CourseMapper;
import com.hmh.student.students.service.ICourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmh.student.students.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xyf
 * @since 2025-04-16
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements ICourseService {
    @Autowired
    private ITeacherService teacherService;

    private final CourseMapper courseMapper;

    public CourseServiceImpl(CourseMapper courseMapper) {

        this.courseMapper = courseMapper;
    }

    @Override
    public Page<Course> queryCoursePage(String courseName, Integer teacherNo, Integer pageSize, Integer current) {
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        if (courseName != null && !courseName.isEmpty()) {
            wrapper.like("course_name", courseName);
        }
        if (teacherNo != null) {
            wrapper.eq("teacher_no", teacherNo);
        }
        return this.page(new Page<>(current, pageSize), wrapper);
    }

    @Override
    public boolean existsById(Integer courseNo) {
        if (courseNo == null)  return false;
        return courseMapper.selectCount(new QueryWrapper<Course>().eq("course_no", courseNo)) > 0;
    }




}
